package twu.shubham.biblioteca;
import java.util.Scanner;

public class biblioteca {

    public static void main(String args[]){

        int continue1=1;
        int selectmenu ;
        int loginid=0;
        int loginstatus=0;
        int totalbooks=5;
        bookrecord[] booklist = new bookrecord[totalbooks];
        for(int i=0; i<totalbooks; i++){
            booklist[i] = new bookrecord();
        }
         bookValue(booklist)   ;

        int totalmovies=15;
        movierecord[] movielist = new movierecord[totalmovies];
        for(int i=0; i<totalmovies; i++){
            movielist[i] = new movierecord();
        }
        movieValue(movielist)   ;

        int totalmembers=5;
        membersrecord[] memberlist = new membersrecord[totalmembers];
        for(int i=0; i<totalmembers; i++){
            memberlist[i] = new membersrecord();
        }
        memberValue(memberlist)   ;


        System.out.println("Welcome to Library system");

        while(continue1==1)
        {
        System.out.println("Menu : \n1.See all the books\n2.See Movie List\n3.Return a book\n4.See the membership detail\n5.login\n6.Logout\n enter an option");

        Scanner input = new Scanner( System.in );

        selectmenu = input.nextInt();
        if(selectmenu == 1)
        {
            System.out.println("S.no." + "\t"+ "Book");
            for(int i=0;i<totalbooks;i++)

            {
               booklist[i].bookPrint() ;
            }

            System.out.println("Want to reserve a book : 1.Yes\n2.No\n");

            int reservebook;
            reservebook = input.nextInt();

            if(reservebook==1)
            {
                if(loginstatus==1)
                {
                int booknumber;
                System.out.println("Enter the book number : ");
                booknumber = input.nextInt();

                if(booknumber<=totalbooks && booknumber-1>=0)
                {
                      booklist[booknumber-1].reserveBook();

                }

                else
                {
                    System.out.println("Not a Valid book number\n");
                }
                }

                else
                {
                    System.out.println("Login First !!!");
                }
            }



        }

         if(selectmenu==2)
         {
             System.out.println("S.no." + "\t"+ "Movie"+"\t"+"Year"+"\t"+"Director"+"\t"+"Rating"+"\n");
             for(int i=0;i<totalmovies;i++)

             {
                // System.out.println(i+1 +"\t\t" + movielist[i].movie +"\t"+ movielist[i].year +
                 // "\t"+movielist[i].director+"\t\t"+ movielist[i].rate);

                movielist[i].moviePrint() ;
             }
         }

        if(selectmenu==3)
        {
            if(loginstatus==1)
            {
            System.out.println("Enter the book number");
            int booknumber;
            booknumber=input.nextInt();
            if(booknumber<=totalbooks && booknumber-1>=0)
            {
                booklist[booknumber-1].returnBook();
            }
            else
            {
                System.out.println("Not a valid book number");
            }
            }
            else
            {
                System.out.println("Login First !!!");
            }

        }
            if(selectmenu==4)
            {
                if(loginstatus==0)
                {
                    System.out.println("Login First !!!");
                }

                else
                {
                    int done=0;
                    for(int i=0;i<totalmembers && done==0;i++)
                    {
                        if(memberlist[i].librarynumber==loginid)
                        {
                            memberlist[i].printDetail();
                            done=1 ;
                        }
                    }
                }
            }

            if(selectmenu==5)
            {
                if(loginstatus==0)
                {
                System.out.println("Login, Enter Library number : ");
                int lib=input.nextInt();
                for(int i=0;i<totalmembers && loginstatus==0;i++)
                {
                    if(memberlist[i].librarynumber==lib)
                    {
                        System.out.println("Enter Password : ");
                        int pass = input.nextInt();
                        if(pass==memberlist[i].password)
                        {
                            loginstatus=1;
                            loginid=lib;
                            System.out.println("You are logged in");
                        }
                    }


                }
                }
                else
                {
                    System.out.println("Already Logged in\n");
                }
                if(loginstatus==0)
                {
                    System.out.println("Either Wrong library number or Password\n");
                }

            }

            if(selectmenu==6)
            {
                if(loginstatus==1)
                {
                    loginstatus=0;
                    loginid=0;
                    System.out.println("Thank you\n");
                }
                else
                {
                    System.out.println("No user is logged in\n");
                }
            }


            System.out.println("Do You want to continue : 1.Yes\t2.No\n");
            continue1=input.nextInt();

        }




    }

    public static  void bookValue(bookrecord booklist[])
    {
        booklist[0].setValues(1,2,"a");
        booklist[1].setValues(2,0,"b");
        booklist[2].setValues(3,1,"c");
        booklist[3].setValues(4,4,"d");
        booklist[4].setValues(5,5,"e");
    }

    public static  void movieValue(movierecord movielist[])
    {        //order : s/no, movie, year, director, rating
        movielist[0].setValues(1,"Sholay",1975,"R.Sippy",7);
        movielist[1].setValues(2,"Guide",2008,"R.Mehra",7);
        movielist[2].setValues(3,"Satya",1976,"P.Sippy",7);
        movielist[3].setValues(4,"Tiranga",1977,"S.Sippy",7);
        movielist[4].setValues(5,"Anand",1978,"T.Sippy",7);
        movielist[5].setValues(6,"Aamir",2008,"R.Mehra",7);
        movielist[6].setValues(7,"Chennai",2008,"R.Mehra",7);
        movielist[7].setValues(8,"Express",2008,"R.Mehra",7);
        movielist[8].setValues(9,"Dabbang",2008,"R.Mehra",7);
        movielist[9].setValues(10,"Wanted",2008,"R.Mehra",7);
        movielist[10].setValues(11,"Players",2008,"R.Mehra",7);
        movielist[11].setValues(12,"Black",2008,"R.Mehra",7);
        movielist[12].setValues(13,"xyzzz",2008,"R.Mehra",7);
        movielist[13].setValues(14,"Maachis",2008,"R.Mehra",7);
        movielist[14].setValues(15,"Krati",2008,"R.Mehra",7);
    }

    public static void memberValue(membersrecord memberlist[])
    {          //order : s/no, librarynum, name, password, phone, email
        memberlist[0].setValues(1,1111111,"Ankit",100,"554432","ankit@gmail.com");
        memberlist[1].setValues(2,1111112,"Abhi",101,"554433","abhi@gmail.com");
        memberlist[2].setValues(3,1111113,"Rohit",102,"554434","rohit@gmail.com");
        memberlist[3].setValues(4,1111114,"Amit",103,"554435","amit@gmail.com");
        memberlist[4].setValues(5,1111115,"Ankita",104,"554436","ankita@gmail.com");
    }

}

